package com.batata.continuing.service.common;

import com.batata.continuing.utils.JwtUtil;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

@Service
public class CommonService {


    /**
     * 根据requset获取token
     * @return
     */
    public String getTokenByRequest(HttpServletRequest request) {
        return request.getHeader("token");
    }


    /**
     * 根据token获取用户id
     * @return
     */
    public String getUseridByToken(String token) {
        return JwtUtil.getUserId(token);
    }

    /**
     * 根据request 获取 用户id
     * @return
     */
    public String getUserIdByRequest(HttpServletRequest request) {
        return getUseridByToken(getTokenByRequest(request));
    }





}
